package teaching.io.base;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 字节输入流示例。
 * 
 * @author deng.zhao
 * @version 1.0 2018/03/28
 *
 */
public class InputStreamExample {

	public static void main(String[] args) {
		
		int length;
		byte[] buf = new byte[1024];

		try (InputStream is = new FileInputStream("d:/test.dat");) {
			while ((length = is.read(buf)) != -1) {
				System.out.print(new String(buf, 0, length));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println("DONE!");
	}

}
